package com.tfj.mvp.tfj.detail.buildinfo;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hyphenate.tfj.R;
import com.jarvislau.destureviewbinder.GestureViewBinder;
import com.tfj.mvp.base.BaseActivity;
import com.tfj.mvp.tfj.detail.buildinfo.bean.BuildInfoBean;
import com.tfj.mvp.tfj.detail.buildinfo.bean.BuildTagBean;
import com.tfj.utils.AntiShakeUtils;
import com.tfj.utils.NoScrollViewManager;
import com.tfj.utils.SysUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Hq on 2017/12/21.
 *
 * @author HuangQiang
 * @github https://github.com/HuangQiang
 */

public class VBuildInfoActivity extends BaseActivity<PBuildInfoImpl> implements CBuildInfo.IVBuildInfo {


    @BindView(R.id.targetView)
    RelativeLayout targetView;
    @BindView(R.id.groupView)
    LinearLayout groupView;
    @BindView(R.id.recyclerView_tag)
    RecyclerView recyclerViewTag;
    @BindView(R.id.textView_starttime)
    TextView textViewStarttime;
    @BindView(R.id.textView_intime)
    TextView textViewIntime;
    @BindView(R.id.textView_level)
    TextView textViewLevel;
    @BindView(R.id.textView_source)
    TextView textViewSource;
    @BindView(R.id.textView_unit)
    TextView textViewUnit;
    @BindView(R.id.textView_count)
    TextView textViewCount;
    @BindView(R.id.recycleView_content)
    RecyclerView recycleViewContent;
    @BindView(R.id.btn_chat)
    Button btnChat;
    @BindView(R.id.btn_tel)
    Button btnTel;
    @BindView(R.id.nestView)
    NestedScrollView nestView;
    private int imageWidth = 0;
    @Override
    protected void initView() {
        super.initView();
        setTitleText("楼栋信息");
        imageWidth = SysUtils.getWidth(this)/2-SysUtils.dip2px(this,64)/2;
        groupView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v.getId() == R.id.groupView&&event.getAction() == MotionEvent.ACTION_DOWN) {
                    nestView.requestDisallowInterceptTouchEvent(true);
                }
                return false;
            }
        });
        targetView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v.getId() == R.id.targetView&&event.getAction() == MotionEvent.ACTION_DOWN) {
                    nestView.requestDisallowInterceptTouchEvent(true);
                }
                return false;
            }
        });
        GestureViewBinder bind = GestureViewBinder.bind(this, groupView, targetView);
        bind.setFullGroup(true);
        bind.setOnScaleListener(new GestureViewBinder.OnScaleListener() {
            @Override
            public void onScale(float scale) {
                Log.i("TAG", scale + "");
            }
        });
        ViewGroup.LayoutParams layoutParams = targetView.getLayoutParams();
        layoutParams.width = (int) (SysUtils.getWidth(this) * 1.3);
        layoutParams.height = (int) (SysUtils.getWidth(this) * 1.3);
        targetView.setLayoutParams(layoutParams);
        //标签
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerViewTag.setAdapter(quickAdapter_tag);
        recyclerViewTag.setLayoutManager(linearLayoutManager);
        List<BuildTagBean> buildTagBeanList = new ArrayList<>();
        buildTagBeanList.add(new

                BuildTagBean("10#"));
        buildTagBeanList.add(new

                BuildTagBean("12#"));
        buildTagBeanList.add(new

                BuildTagBean("13#"));
        buildTagBeanList.add(new

                BuildTagBean("14#"));
        buildTagBeanList.add(new

                BuildTagBean("4#"));
        buildTagBeanList.add(new

                BuildTagBean("155#"));
        buildTagBeanList.add(new

                BuildTagBean("154#"));
        quickAdapter_tag.replaceData(buildTagBeanList);
        //楼栋户型
        NoScrollViewManager noScrollViewManager = new NoScrollViewManager(this);
        noScrollViewManager.setScrollEnabled(false);
        recycleViewContent.setLayoutManager(noScrollViewManager);
        recycleViewContent.setAdapter(quickAdapter_buildInfo);
        recycleViewContent.setNestedScrollingEnabled(false);
        List<BuildInfoBean> buildInfoBeans = new ArrayList<>();
        buildInfoBeans.add(new

                BuildInfoBean());
        buildInfoBeans.add(new

                BuildInfoBean());
        buildInfoBeans.add(new

                BuildInfoBean());
        buildInfoBeans.add(new

                BuildInfoBean());
        buildInfoBeans.add(new

                BuildInfoBean());
        quickAdapter_buildInfo.replaceData(buildInfoBeans);


    }

    @Override
    public int setContentViewId() {
        return R.layout.activity_buildinfo;
    }

    @Override
    public void createPresenter() {
        mPresenter = new PBuildInfoImpl(mContext, this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    private QuickAdapter_Tag quickAdapter_tag = new QuickAdapter_Tag();
    private int checkIndex = 0;

    public class QuickAdapter_Tag extends BaseQuickAdapter<BuildTagBean, BaseViewHolder> {
        public QuickAdapter_Tag() {
            super(R.layout.item_build_tag);
        }

        @Override
        protected void convert(BaseViewHolder viewHolder, final BuildTagBean item) {
            TextView textView_Tag = viewHolder.getView(R.id.textView_Tag);
            RelativeLayout rl_out = viewHolder.getView(R.id.rl_out);
            if (viewHolder.getAdapterPosition() == checkIndex) {
                textView_Tag.setTextColor(getResources().getColor(R.color.color_check_log));
                textView_Tag.setTextSize(23);
            } else {
                textView_Tag.setTextColor(getResources().getColor(R.color.color_uncheck_log));
                textView_Tag.setTextSize(18);
            }
            rl_out.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (AntiShakeUtils.isInvalidClick(v))
                        return;
                    checkIndex = viewHolder.getAdapterPosition();
                    quickAdapter_tag.notifyDataSetChanged();
                }
            });
            textView_Tag.setText(item.getName());
        }
    }

    private QuickAdapter_BuildInfo quickAdapter_buildInfo = new QuickAdapter_BuildInfo();

    public class QuickAdapter_BuildInfo extends BaseQuickAdapter<BuildInfoBean, BaseViewHolder> {
        public QuickAdapter_BuildInfo() {
            super(R.layout.item_buildinfo);
        }

        @Override
        protected void convert(BaseViewHolder viewHolder, final BuildInfoBean item) {
            ImageView imageView = viewHolder.getView(R.id.imageView);
            ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
            layoutParams.width = imageWidth;
            imageView.setLayoutParams(layoutParams);
        }
    }
}
